package snow.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * 自定义Filter
 * @author : liqun
 * @createTime : 2022/2/22 11:00
 */
@WebFilter(filterName = "UrlFilter",urlPatterns = {"/*"})
public class UrlFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
        String url = httpServletRequest.getRequestURI();
        System.out.println("请求URL："+url);
        filterChain.doFilter(httpServletRequest,servletResponse);
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("filter初始化。。。");
    }

    @Override
    public void destroy() {
        System.out.println("filter销毁。。。");
    }
}
